package org.shoukaiseki.ddcs.actuator.config;

import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;

public class ConfigYaml  {

    private static Map conf=null;

   public static void loadYaml(InputStream inputStream){
       Yaml yaml=new Yaml();
       conf =yaml.load(inputStream);

   }


    public static String getString(String key){
       Object o=getObject(key);
       if(o instanceof Integer){
           return String.valueOf(o);
       }
        return (String)getObject(key);
    }


    public static Object getObject(String key){
        Object value=null;
        String[] split = key.split("\\.");
        Map map=conf;
        for (String k:split ) {
            Object o=map.get(k);
            value=o;
            if(o instanceof Map){
               map= (Map) o;
            }
        }


        return value;
    }



}
